package com.three.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author wzm
 * @create 2023-11-08 16:49
 * project_name:web2310
 * @Description
 */
//在访问资源之前设置编码
//@WebFilter("/user/*")
//@WebFilter("/index.jsp")
//@WebFilter("/index.html")
//@WebFilter("*.jsp")
@WebFilter("/*")
public class EncodingFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("设置编码前");
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        chain.doFilter(request,response);
        System.out.println("设置编码后");
    }

    @Override
    public void destroy() {

    }
}
